<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
    <style>
        .loading{
            width: 100px;
            height: 100px;
            position:absolute;
            top: 50%;
            left:50%;
            margin-top: -50px;
            margin-left: -50px;
            animation: run 2s linear infinite;
            display: none;
        }
        img{
            width: 100%;
            height: 100%;
        }

        @keyframes run {
            from{
                transform: rotate(0deg);
            }
            to{
                transform: rotate(360deg);
            }
        }

        
    </style>
</head>
<body>
    <button>获取按钮</button>
    <div class="loading"><img src="./img/loading.jpg" /></div>
    <script>
        let btn= document.querySelector('button');
        let loadbox= document.querySelector('.loading');

        axios.interceptors.request.use(config=>{
            // 显示loading图片
            loadbox.style.display = 'block'
            return config;
        })

        axios.interceptors.response.use(res=>{
            loadbox.style.display = 'none'

            return res;
        })

        btn.onclick= function(){
            axios({
                url:"http://localhost:3000/users"
            }).then(val=>{
                console.log(val);
            })
        }
    </script>
</body>
</html>